package com.briup.mt.service.impl;


import com.briup.mt.bean.BaseFile;
import com.briup.mt.bean.BaseFileExample;
import com.briup.mt.dao.BaseFileMapper;
import com.briup.mt.service.IBaseFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseFileServiceImpl implements IBaseFileService {
    @Resource
    @Autowired
    private BaseFileMapper baseFileMapper;
    @Override
    public List<BaseFile> query(String id,String name) {
        BaseFileExample example = new BaseFileExample();
        if (!StringUtils.isEmpty(name)) {
            example.createCriteria().andFileNameLike("%" + name + "%");
        }
        if(!StringUtils.isEmpty(id)){
            example.createCriteria().andIdEqualTo(id);
        }
        List<BaseFile> list=baseFileMapper.selectByExample(example);
        return list;
    }


    @Override
    public void saveOrUpdate(BaseFile baseFile) {
        if(baseFile.getId()==null) {
            baseFileMapper.insert(baseFile);
        }else{
            baseFileMapper.updateByPrimaryKey(baseFile);
        }

    }

    @Override
    public void deleteById(String id) {
        baseFileMapper.deleteByPrimaryKey(id);
    }

}